package com.carrot.uaa.infrastructure.service;

import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.carrot.uaa.entity.OAuth2User;
import com.carrot.uaa.entity.SysUserLoginLog;
import com.carrot.uaa.infrastructure.mapper.SysUserLoginLogMapper;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 */
@Service
public class SysUserLoginLogServiceImpl extends ServiceImpl<SysUserLoginLogMapper, SysUserLoginLog>
        implements SysUserLoginLogService {

    @Override
    public void save(OAuth2User oAuth2User, String clientIp) {
        SysUserLoginLog sysUserLoginLog=new SysUserLoginLog();
        sysUserLoginLog.setId(IdUtil.getSnowflakeNextId());
        sysUserLoginLog.setUserId(Long.valueOf(oAuth2User.getUid()));
        sysUserLoginLog.setLoginTime(LocalDateTime.now());
        sysUserLoginLog.setLoginIp(clientIp);
        sysUserLoginLog.setLoginForm("0");
        this.save(sysUserLoginLog);
    }
}
